package org.example.view.Frame;

import org.example.view.componet.ATMButton;
import org.example.view.componet.BackgroundScene;
import org.example.view.componet.ButtonTypeEnum;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * 主页
 */
public class MainAtm extends JPanel {
    /**
     * 背景
     */
    private BackgroundScene backgroundScene;
    /**
     * 登录按钮
     */
    private ATMButton loginButton;
    /**
     * 退出按钮
     */
    private ATMButton offButton;
    /**
     * 注册按钮
     */
    private ATMButton registerButton;

    public MainAtm(JPanel panel) {
        this.addContent(panel);
    }

    private void addContent(JPanel panel) {
        this.setLayout(null);

        /**
         * 登录按钮
         */
        this.loginButton = new ATMButton(ButtonTypeEnum.登陆, 20, 665);
        this.loginButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "login");
            }
        });
        this.add(this.loginButton);

        /**
         * 退出按钮
         */
        this.offButton = new ATMButton(ButtonTypeEnum.退出, 450, 650);
        this.offButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        this.add(this.offButton);

        /**
         * 注册按钮
         */
        this.registerButton = new ATMButton(ButtonTypeEnum.注册, 830, 665);
        this.registerButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "register");
            }
        });
        this.add(this.registerButton);

        /**
         * 背景
         */
        this.backgroundScene = new BackgroundScene();
        this.add(this.backgroundScene);
    }

}
